import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Scanner;

public class Test2 {
    private static void read(){
        /*InputStream inputStream = new FileInputStream("./test.txt");
        while (true){
            int ch= inputStream.read();
            if (ch == -1){
                break;
            }
            System.out.printf("%c",ch);
        }
        inputStream.close();*/
        //更好的写法
        try (InputStream inputStream = new FileInputStream("test.txt")){
            while (true){
                int s = inputStream.read();
                if (s == -1){
                    break;
                }
                System.out.printf("%c",s);
            }
        }catch (IOException e){
            e.printStackTrace();
        }
    }
    private static void read1024(){
        try (InputStream inputStream = new FileInputStream("test.txt")){
            byte[] bytes = new byte[1024];
            while (true){
                int n =inputStream.read(bytes);
                if (n == -1){
                    break;
                }
                for (int i = 0; i < n; i++) {
                    System.out.printf("%c",bytes[i]);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    private static void readMinPlus(){
        try (InputStream inputStream = new FileInputStream("test.txt")){
           while (true){
               byte[] bytes = new byte[1024];
               int n = inputStream.read(bytes);
               if (n == -1){
                   break;
               }
               for (int i = 0; i < n; i+=3) {
                   String s = new String(bytes,i,3,"UTF-8");
                   System.out.println(s);
               }
           }
        }catch (IOException e){
            e.printStackTrace();
        }
    }
    private static void readPlus(){
        try (InputStream inputStream = new FileInputStream("test.txt")){
            Scanner scanner = new Scanner(inputStream,"UTF-8");
            while (scanner.hasNextLine()){
                String s = scanner.next();
                System.out.println(s);
            }
        }catch (IOException e){
            e.printStackTrace();
        }
    }
    public static void main(String[] args) throws IOException {
        read();
    }
}
